package com.huike.web.controller.clues;

import java.util.Date;
import java.util.List;

import com.huike.clues.service.ITbClueService;
import com.huike.clues.service.impl.TbClueTrackRecordServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.huike.clues.domain.TbClue;
import com.huike.clues.domain.TbClueTrackRecord;
import com.huike.clues.domain.vo.ClueTrackRecordVo;
import com.huike.clues.service.ITbClueTrackRecordService;
import com.huike.common.annotation.Log;
import com.huike.common.core.controller.BaseController;
import com.huike.common.core.domain.AjaxResult;
import com.huike.common.core.page.TableDataInfo;
import com.huike.common.enums.BusinessType;
import com.huike.common.utils.DateUtils;
import com.huike.common.utils.SecurityUtils;

/**
 * 线索跟进记录Controller
 *
 * @date 2021-04-22
 */
@RestController
@RequestMapping("/clues/record")
public class TbClueTrackRecordController extends BaseController {
    @Autowired
    private TbClueTrackRecordServiceImpl tbClueTrackRecordService;
    @Autowired
    private ITbClueService tbClueService;

    @PostMapping
    public AjaxResult record(@RequestBody ClueTrackRecordVo clueTrackRecordVo){

        //Vo接得住所有来自前端的信息，里面包含clue表的weixin qq等数据
        TbClue tbClue = new TbClue();
        BeanUtils.copyProperties(clueTrackRecordVo,tbClue);
        Long clueId = clueTrackRecordVo.getClueId();
        tbClue.setId(clueId);
        tbClueService.updateTbClue(tbClue);
        tbClueTrackRecordService.InsereClueTrackRecordVo(clueTrackRecordVo);
        return AjaxResult.success();
    };

    @GetMapping("/list")
    public TableDataInfo list(Long clueId){

        List<TbClueTrackRecord> tbClueTrackRecords = tbClueTrackRecordService.selectTbClueTrackRecordListByClueId(clueId);
        //getDataTable
        return getDataTable(tbClueTrackRecords);
    }
}